<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width: 400px;
            height: 600px;
            margin: auto;
            outline: 2px solid red;
            display: flex;
            flex-direction: column;
            
        }
        .list{
            height: 50px;
            overflow: hidden;
        }
        .list h2{
            height: 50px;
            background-color: gray;
        }
        .active{
            flex-grow: 1;

        }
    </style>
</head>
<body>
    <div class="box">
        <div class="list active">
            <h2>电影</h2>
            <ul>
                <li>1</li>
                <li>1</li>
                <li>1</li>
                <li>1</li>
                <li>1</li>
                <li>1</li>
                <li>1</li>
            </ul>
        </div>
        <div class="list">
            <h2>书籍</h2>
            <ul>
                <li>1</li>
                <li>1</li>
                <li>1</li>
                <li>1</li>
                <li>1</li>
                <li>1</li>
                <li>1</li>
            </ul>
        </div>
        <div class="list">
            <h2>音乐</h2>
            <ul>
                <li>1</li>
                <li>1</li>
                <li>1</li>
                <li>1</li>
                <li>1</li>
                <li>1</li>
                <li>1</li>
            </ul>
        </div>
        <div class="list">
            <h2>游戏</h2>
            <ul>
                <li>1</li>
                <li>1</li>
                <li>1</li>
                <li>1</li>
                <li>1</li>
                <li>1</li>
                <li>1</li>
            </ul>
        </div>
        <div class="list">
            <h2>动漫</h2>
            <ul>
                <li>1</li>
                <li>1</li>
                <li>1</li>
                <li>1</li>
                <li>1</li>
                <li>1</li>
                <li>1</li>
            </ul>
        </div>
    </div>

    <script>
        let box=document.getElementsByClassName("box")[0];
        let list=document.getElementsByClassName("list");
        box.onclick=function(){
            console.log(event.target);
            if(event.target.localName=="h2"){
                for(let i=0;i<list.length;i++){
                    list[i].classList.remove("active");
                }

                event.target.parentNode.classList.add("active");
            }
        }

    </script>
</body>
</html>